package com.maxatime.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.maxatime.common.constant.BusinessContents;

import com.maxatime.pojo.entity.ExamStorage2;
import com.maxatime.service.Ssbkaoshi4;
import com.maxatime.util.MyContent;

//vue12月份考试
@Controller
@RequestMapping("/Ssbkaoshi4")
public class Ssbcontroller4 {
	@Autowired
	Ssbkaoshi4 ssbkaoshi4;

//	@RequestMapping("/cha")
//	public String cha() {
//		return "Ssbks4/kaoshi";
//	}
	
	// 查询
	@RequestMapping("/quest")
	@ResponseBody
	public Map<String, Object> quest(@RequestBody String jsonStr) {
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		String goodsName = jsonObj.getString("goodsName");
		String goodsType = jsonObj.getString("goodsType");
		int pageNum = jsonObj.getIntValue("pageNum");
		int pageSize = jsonObj.getIntValue("pageSize");
		Map<String, Object> m = new HashMap<>();
		ExamStorage2 examStorage2 = new ExamStorage2();
		examStorage2.setGoodsName(goodsName);
		examStorage2.setGoodsType(goodsType);
		examStorage2.setPageNum(pageNum);
		examStorage2.setPageSize(pageSize);
		Map<String, Object> list = ssbkaoshi4.list(examStorage2);
		m.put(BusinessContents.CODE, "0000");
		m.put(BusinessContents.MSG, "交易成功");
		m.put(BusinessContents.DATA, list.get("list"));
		m.put("pageInfo", list.get("pageInfo"));
		return m;

	}

	// 新增
	@RequestMapping("/save")
	@ResponseBody
	public Map<String, Object> save(@RequestBody ExamStorage2 examStorage2) {
		Map<String, Object> m = new HashMap<>();
		ssbkaoshi4.insertSelective(examStorage2);
		m.put(MyContent.CODE, "1111");
		m.put(MyContent.MSG, "新增成功");
		return m;
	}

	// 删除
	@RequestMapping("/delete")
	@ResponseBody
	public Map<String, Object> delete(@RequestBody String jsonStr) {
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkId = jsonObj.getInteger("pkId");
		Map<String, Object> m = new HashMap<>();
		ssbkaoshi4.deleteByPrimaryKey(pkId);
		m.put(MyContent.CODE, "2222");
		m.put(MyContent.MSG, "删除成功");
		return m;
	}

	// 修改反显
	@RequestMapping("/find")
	@ResponseBody
	public Map<String, Object> find(@RequestBody String jsonStr) {
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkId = jsonObj.getInteger("pkId");
		Map<String, Object> m = new HashMap<>();
		ExamStorage2 examStorage2 = ssbkaoshi4.findpkId(pkId);
		m.put(MyContent.CODE, "3333");
		m.put(MyContent.MSG, "反显成功");
		m.put(MyContent.DATA, examStorage2);
		return m;
	}
	
	// 修改
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(@RequestBody ExamStorage2 examStorage2) {
		Map<String, Object> m = new HashMap<>();
		ssbkaoshi4.updateByPrimaryKeySelective(examStorage2);
		m.put(MyContent.CODE, "4444");
		m.put(MyContent.MSG, "修改成功");
		return m;
	}

}
